package com.example.ayareimburse;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity 
{
	private FileProcessor clsFProcessor = new FileProcessor();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		Button btnNew =(Button) this.findViewById(R.id.btnNew);
		Button btnChange =(Button) this.findViewById(R.id.btnChange);
		Button btnMain =(Button) this.findViewById(R.id.btnMain);
		Button btnRtn =(Button) this.findViewById(R.id.btnRtn);
		
		TextView tbNum =(TextView) this.findViewById(R.id.tbNum);
		
		btnNew.setOnClickListener(new btnNewClickListener(tbNum));
		btnChange.setOnClickListener(new btnChangeClickListener(tbNum));
		btnMain.setOnClickListener(new btnMainClickListener(tbNum));
		btnRtn.setOnClickListener(new btnRtnClickListener(tbNum));
		//*************************************************************
		//TextView tbTest =(TextView) this.findViewById(R.id.tbTest);
		//*************************************************************
		
		String strCntFile = clsFProcessor.getCurrentFile();
		if (strCntFile.length() == 3)
		{
			tbNum.setText(strCntFile);
		}
		else
		{
			tbNum.setHint(strCntFile.substring(1));
		}
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) 
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	private class btnNewClickListener implements View.OnClickListener
	{
		private TextView tbNum;
		
		public btnNewClickListener(TextView pNum)
		{
			tbNum = pNum;
		}
		
	    public void onClick(View v) 
	    {	 
	    	clsFProcessor.createNew();
	    	refresh(tbNum);
	    }
	     
	 }
	
	private class btnChangeClickListener implements View.OnClickListener
	{
		private TextView tbNum;
		
		public btnChangeClickListener(TextView pNum)
		{
			tbNum = pNum;
		}
		
	    public void onClick(View v) 
	    {	    	
	    	clsFProcessor.changeSave();
	    	refresh(tbNum);
	    }
	     
	}
	
	private class btnMainClickListener implements View.OnClickListener
	{
		private TextView tbNum;
		
		public btnMainClickListener(TextView pNum)
		{
			tbNum = pNum;
		}
		
	    public void onClick(View v) 
	    {	    	
	    	clsFProcessor.getMainSave();
	    	refresh(tbNum);
	    }
	     
	}
	
	private class btnRtnClickListener implements View.OnClickListener
	{
		private TextView tbNum;
		
		public btnRtnClickListener(TextView pNum)
		{
			tbNum = pNum;
		}
		
	    public void onClick(View v) 
	    {	    	
	    	clsFProcessor.getLastSaveBack();
	    	refresh(tbNum);
	    }
	     
	}
	
	private void refresh(TextView tbNum)
	{
		String strCntFile = clsFProcessor.getCurrentFile();
		if (strCntFile.length() == 3)
		{
			tbNum.setText(strCntFile);
		}
		else
		{
			tbNum.setHint(strCntFile.substring(1));
		}
		
//		String fileName = "D:/Android/ayakashi.apk";
//		Intent intent = new Intent(Intent.ACTION_VIEW);
//		intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
//		startActivity(intent);
		
		Uri packageURI = Uri.parse("package:com.zynga.zjayakashi");   
		Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);   
		startActivity(uninstallIntent);
	}
	
}
